#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class compare{

public:
    bool operator()(int i,int j){
        if(to_string(i)[0]=to_string(j)[0]){
            return to_string(i)+to_string(j)<to_string(j)+to_string(i);
        }
        return to_string(i)[0]<to_string(j)[0];
    }

};

class Solution {
public:
    string minNumber(vector<int>& nums) {
        //贪心算法
        if(nums.size()==1){
            return to_string(nums[0]);
        }
        sort(nums.begin(),nums.end(),compare());
        int i = 0;
        string result = "";
        while(i<nums.size()){
            
                result += to_string(nums[i]);
                ++i;
            
        }
        return result;
        
    }
};

int main(){
    Solution S;
    vector<int> nums = {3,30,34,5,9};
    cout<<S.minNumber(nums)<<endl;
}